<template>
    <div>
        <h3>房号添加</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">房型</td>
                    <td>
                        <select v-model="querinfo.HouseTypeId">
                            <option value="">请选择</option>
                            <option :value="item.Id" v-for="item in data.list">{{ item.HouseName }}</option>
                        </select>
                    </td>
                </tr>

                <tr>
                    <td align="right">房间号码</td>
                    <td>
                        <input type="text" v-model="querinfo.HouseNoName">
                    </td>
                </tr>

                <tr>
                    <td align="right">房号描述</td>
                    <td>
                        <textarea cols="30" rows="5" v-model="querinfo.HouseNoDesc"></textarea>
                    </td>
                </tr>

                <tr>
                    <td align="right">状态</td>
                    <td>
                        <input type="radio" name="State" :value="1" v-model="querinfo.State">上架
                        <input type="radio" name="State" :value="0" v-model="querinfo.State">下架
                    </td>
                </tr>

                <tr>
                    <td align="right"></td>
                    <td>
                        <input type="button" value="添加" @click="ok" class="btn btn-primary">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { ref,reactive,onMounted } from 'vue';
import { useRoute,useRouter } from 'vue-router';
const route=useRoute();
const router=useRouter();

let querinfo:any=reactive({
  "HouseTypeId": "",
  "HouseNoName": "",
  "HouseNoDesc": "",
  "State": "",
})
let data:any=reactive({
    list:[],

})
onMounted(()=>{
    getList();
})

const ok=()=>{
    axios({
        method:"post",
        url:"/api/House/HouseNoAdd",
        data:querinfo
    })
    .then(res=>{
        if(res.data==-1){
            alert('房号重复')
        }
        else if(res.data>0){
            alert('添加成功')
            router.push('/houseNoList')
        }
    })
    .catch(err=>{
        console.log(err)
    })
}


//显示
const getList=()=>{
    axios({
        method:"get",
        url:"/api/House/HouseTypeShow",
        params:{
            pageSize:100
        }
    })
    .then(res=>{
        console.log(res)
        data.list=res.data.list
    })
}
</script>





<style scoped>

</style>